<template>
    <!--添加合伙人弹框-->
    <el-dialog title="LP情况："
               :visible="addDialog"
               :close-on-click-modal="false"
               :before-close="cancelDialog"
               :show-close="false"
                class="dialog_self">
        <el-form :model="partnerEntity" :rules="rules" ref="ruleForm" label-width="100px">
            <el-row class="ca-p-r-20">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="潜在LP">
                            <el-select v-model="partnerEntity.lpId" @change="changeLp" filterable placeholder="请选择" class="ca-w-100">
                                <el-option
                                    v-for="item in guest"
                                    :key="item.guestId"
                                    :label="item.guestName"
                                    :value="item.guestId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="投资状态">
                            <el-select v-model="partnerEntity.state" placeholder="请选择" class="ca-w-100">
                                <el-option
                                    v-for="item in fundPartnerOptionsAdd"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="服务人">
                            <el-input v-model="partnerEntity.serviceMan" :maxlength="100"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="拟投资金额" prop="investAmount">
                            <el-input v-model="partnerEntity.investAmount" placeholder="万元" :maxlength="21" class="ca-w-100"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="募资纪录">
                            <el-input type="textarea" v-model="partnerEntity.record" :maxlength="3000" placeholder="最多输入3000字"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item label="相关文档">
                        <el-row>
                            <div class="ca-inline-block ca-m-r-10 ">
                                <csUpload
                                    :fileType="fileType"
                                    :businessId="itemId"
                                    :isShowFileChildType="false"
                                    uploadType="all"
                                    @getFileList="getPartnerDetail"
                                    :getFileUploadedReturnData="getFileUploadedReturnDataFun"
                                ></csUpload>
                            </div>
                        </el-row>
                        <el-row class="ca-file-row" v-for="(file, editIndex) in fileDetail" :key="editIndex">
                            <el-col :span="2">
                                <tz-icon-file-type class="ca-m-r-5" :fileType="file.fileName"></tz-icon-file-type>
                            </el-col>
                            <el-col :span="10">
                                <div class="ca-text-over-flow-ellipsis ca-pointer">
                                    <span class="ca-font-size-16 ca-pointer">{{file.fileName}}</span>
                                </div>
                            </el-col>
                            <el-col :span="3">
                                <el-button class="ca-table-btn" @click="deleteFileItem(editIndex)">
                                    <i class="fa fa-times"></i>
                                </el-button>
                            </el-col>
                        </el-row>
                    </el-form-item>
                </el-row>
            </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer ca-m-b-20">
            <el-button @click="cancelDialog">取 消</el-button>
            <el-button type="primary" @click="addFundPartner">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script type="text/ecmascript-6">
    export default {
        data() {
            var validateNumber = (rule, value, callback) => {
                var reg = /^\d{1,10}(\.\d{1,10})?$/;
                if (value && (!reg.test(value))) {
                    callback(new Error('请输入正确范围的数字'));
                } else {
                    callback();
                }
            };
            return {
                itemId: this.$route.params.itemId,
                guest: this.$store.state.user.guest,
                fundPartnerOptionsAdd: this.$store.state.user.dictionaryMap.ansatLp,//弹框筛选
                fileType: this.$store.state.user.fileFloderDicVoList[48].type,//基金文件类型
                rules: {
                    investAmount: [
                        { validator: validateNumber, trigger: 'blur' }
                    ],
                },
            }
        },
        props: ['partnerEntity', 'addDialog', 'fileDetail'],
        methods: {
            // 改变潜在LP时赋值
            changeLp(val) {
                this.guest.map(item=>{
                    if (item.guestId === val) {
                        this.partnerEntity.lpName = item.guestName;
                    }
                })
            },
            // 取消
            cancelDialog() {
                this.$emit('cancelDialog')
            },
            // 添加
            addFundPartner() {
                this.$refs.ruleForm.validate(async (valid) => {
                    if (valid) {
                        this.$emit('addFundPartner')
                    }
                })
            },
            // 文件成功返回的数据
            getFileUploadedReturnDataFun(arr) {
                this.$emit('getFileUploadedReturnDataFun', arr)
            },
            // 添加后获取详情
            getPartnerDetail() {
                this.$emit('getPartnerDetail')
            },
            // 删除添加时的文件
            deleteFileItem(index) {
                this.$emit('deleteFileItem', index)
            }
        },
        components: {
            'csUpload': require('__components/upload-btn/index'),//上传文件组件
        }
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .ca-w-100 {
        width: 100%;
    }
    .dialog-footer {
        text-align: center;
    }
</style>
